(* Program 1.2 *)

use "ast.sml";

(* a table is list of named integers *)
type table = (id * int) list;

(* update -- given a table, update the identifier-value binding *)
local val rec remove : id * table -> table =
       fn (_, []) => []
	| (i', (i,z)::t) => if i'=i
			    then t
			    else (i,z)::(remove (i', t))
in val update : (table * id * int) -> table =
    fn (t, i, z) => (i,z)::(remove (i, t))
end;

(* the exception NotFound is thrown if an identifier isn't bound *)
exception NotFound of id;

(* lookup -- given a table, find the value bound to a given identifier *)
val rec lookup : (table * id) -> int =
 fn ([], i') => raise (NotFound i')
  | ((i,z)::t, i') => if i'=i
		      then z
		      else lookup (t, i');

val empty = [];
     
use "interp.sml";
